#ifndef Eoncder_H
#define Eoncder_H

//可调旋钮器
//用法:
//主循环之前调用: EncoderInit();
//主循环内调用:
//	EncoderMain();
//旋钮检测时钟源,2ms定时调用: EncoderClock();
#include "main.h"

#define IO_Encoder_A PORT_C_12
#define IO_Encoder_B PORT_C_11
#define IO_Encoder_Key PORT_D_0

#define GPIO_ReadEncoderA MR88FX02_Gpio_Get(IO_Encoder_A)
#define GPIO_ReadEncoderB MR88FX02_Gpio_Get(IO_Encoder_B)
#define GPIO_ReadEncoderKey MR88FX02_Gpio_Get(IO_Encoder_Key)

#define IO_Mode_Encoder_Key() MR88FX02_Gpio_Set_Mode(IO_Encoder_Key, INPUT);
#define IO_Mode_Encoder_A() MR88FX02_Gpio_Set_Mode(IO_Encoder_A, INPUT);
#define IO_Mode_Encoder_B() MR88FX02_Gpio_Set_Mode(IO_Encoder_B, INPUT);

typedef struct
{
	uint8_t ASamping;
	uint8_t BSamping;
	uint8_t ParseEnable;
	uint8_t IsKey;
	uint8_t IsLongKey;

	uint8_t IsLongKeyCount; //间隔1s,检测3次有效代表长按有效
	uint8_t TurnRCount;
	uint8_t TurnLCount;
	uint8_t TurnCount; //旋钮速度 调整
	uint8_t KeyUpCount;
	uint8_t KeyDownCount;
	uint8_t IsTurnR;
	uint8_t IsTurnL;
}EncoderParam_S;
extern EncoderParam_S EncoderParam;
extern bool Encoder_Key;
extern bool Encoder_LongKey;
extern bool Encoder_TurnL;
extern bool Encoder_TurnR;

void EncoderInit(void);
void EncoderMain(void);
void EncoderClock(void);

void Encoder_ParamChangingExit(void);
void Switch_SelectItem(void);

void Encoder_Key_Handler(void);
void Encoder_LongKey_Handler(void);
void Encoder_TurnR_Handler(void);
void Encoder_TurnL_Handler(void);

void Encoder_TurnSpeed(uint8_t param);

#endif
